import { NPopconfirm, NSwitch, NSpace, NButton } from 'naive-ui';
import Permisstion from '@/components/permission/index.vue';

export const getColumns = ({
  enableOrEnable,
  openDialog,
  openResetPasswordDialog,
  handleRole,
  handleDeleteUser,
}: any) => {
  return [
    {
      type: 'selection',
      width: 50,
      align: 'center',
    },
    {
      title: '用户编号',
      key: 'userId',
      align: 'center',
      width: 80,
    },
    {
      title: '用户名称',
      key: 'userName',
      align: 'center',
      ellipsis: { tooltip: true },
    },
    {
      title: '用户昵称',
      key: 'nickName',
      align: 'center',
      ellipsis: { tooltip: true },
    },
    {
      title: '部门',
      key: 'deptName',
      align: 'center',
      ellipsis: { tooltip: true },
      render(row: any) {
        return row?.dept?.deptName || '-';
      },
    },
    {
      title: '手机号码',
      key: 'phonenumber',
      align: 'center',
      width: 120,
    },
    {
      title: '状态',
      key: 'status',
      align: 'center',
      render: (row: any) => (
        <Permisstion hasPermi={['system:user:edit']}>
          <NPopconfirm
            onPositiveClick={() => enableOrEnable(row)}
            v-slots={{
              trigger: () => (
                <NSwitch
                  value={row.status}
                  unchecked-value="1"
                  checked-value="0"
                  size="small"
                  loading={row.switchLoading}
                ></NSwitch>
              ),
            }}
          >
            确定要{row.status === '0' ? '停用' : '启用'}该用户吗？
          </NPopconfirm>
        </Permisstion>
      ),
    },
    {
      title: '创建时间',
      key: 'createTime',
      align: 'center',
      width: 200,
    },
    {
      title: '操作',
      key: 'actions',
      width: 220,
      render: (row: any) => (
        <NSpace>
          <Permisstion hasPermi={['system:user:edit']}>
            <NButton text type="primary" size="tiny" onClick={() => openDialog(row)}>
              修改
            </NButton>
          </Permisstion>
          <Permisstion hasPermi={['system:user:resetPwd']}>
            <NButton text type="primary" size="tiny" onClick={() => openResetPasswordDialog(row)}>
              重置密码
            </NButton>
          </Permisstion>
          <Permisstion hasPermi={['system:user:edit']}>
            <NButton text type="primary" size="tiny" onClick={() => handleRole(row)}>
              分配角色
            </NButton>
          </Permisstion>
          <Permisstion hasPermi={['system:user:remove']}>
            <NPopconfirm
              positiveText="确定"
              negativeText="取消"
              onPositiveClick={() => handleDeleteUser(row)}
              v-slots={{
                trigger: () => (
                  <NButton text type="error" size="tiny">
                    删除
                  </NButton>
                ),
              }}
            >
              确定删除该用户吗？
            </NPopconfirm>
          </Permisstion>
        </NSpace>
      ),
    },
  ];
};
